import request from '@/utils/request'
import qs from 'qs'

export function findListByPage(params) {
  return request({
    url: 'api/sourceInfo' + '?' + qs.stringify(params, { indices: false }),
    method: 'get'
  })
}

export function findListByCheck(params) {
  return request({
    url: 'api/sourceInfo/check' + '?' + qs.stringify(params, { indices: false }),
    method: 'get'
  })
}

export function findDefaultSource(params) {
  return request({
    url: 'api/sourceInfo/findDefaultSource',
    method: 'get'
  })
}

export function add(data) {
  return request({
    url: 'api/sourceInfo',
    method: 'post',
    data
  })
}

export function edit(data) {
  return request({
    url: 'api/sourceInfo',
    method: 'put',
    data
  })
}

export function updateIsDefault(data) {
  return request({
    url: 'api/sourceInfo/updateIsDefault',
    method: 'put',
    data
  })
}

export function del(pkIds) {
  return request({
    url: 'api/sourceInfo',
    method: 'delete',
    data: pkIds
  })
}

export function getSourceInfo(pkId) {
  return request({
    url: 'api/sourceInfo/' + pkId,
    method: 'get'
  })
}

export function testConnect(pkId) {
  return request({
    url: 'api/sourceInfo/testConnect/' + pkId,
    method: 'get'
  })
}

export function schemas(pkId) {
  return request({
    url: 'api/sourceInfo/schemas/' + pkId,
    method: 'get'
  })
}

export function tables(params) {
  return request({
    url: 'api/sourceInfo/tables' + '?' + qs.stringify(params, { indices: false }),
    method: 'get'
  })
}

export function procedures(params) {
  return request({
    url: 'api/sourceInfo/procedures' + '?' + qs.stringify(params, { indices: false }),
    method: 'get'
  })
}

export default {
  findListByPage,
  findDefaultSource,
  add,
  edit,
  updateIsDefault,
  del,
  testConnect,
  getSourceInfo,
  findListByCheck,
  schemas,
  tables,
  procedures
}
